class PcolorsController < ApplicationController
  before_filter :load_product,:only=>[:index,:edit,:update,:destroy,:new,:show,:create]
  # GET /pcolors
  # GET /pcolors.xml
  def index
    @pcolors = @product.pcolors.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @pcolors }
    end
  end

  # GET /pcolors/1
  # GET /pcolors/1.xml
  def show
    @pcolor = @product.pcolors.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @pcolor }
    end
  end

  # GET /pcolors/new
  # GET /pcolors/new.xml
  def new
    @pcolor = @product.pcolors.build

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @pcolor }
    end
  end

  # GET /pcolors/1/edit
  def edit
    @pcolor = @product.pcolors.find(params[:id])
  end

  # POST /pcolors
  # POST /pcolors.xml
  def create
     @pcolor = @product.pcolors.build(params[:pcolor])

    respond_to do |format|
      if @pcolor.save
        flash[:notice] = 'pcolor was successfully created.'
        format.html { redirect_to([@product,@pcolor]) }
        format.xml  { render :xml => @pcolor, :status => :created, :location => @pcolor }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @pcolor.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /pcolors/1
  # PUT /pcolors/1.xml
  def update
    @pcolor = @product.pcolors.find(params[:id])

    respond_to do |format|
      if @pcolor.update_attributes(params[:pcolor])
        flash[:notice] = 'pcolor was successfully updated.'
        format.html { redirect_to([@product,@pcolor]) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @pcolor.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /pcolors/1
  # DELETE /pcolors/1.xml
  def destroy
    @pcolor = @product.pcolors.find(params[:id])
    @pcolor.destroy

    respond_to do |format|
      format.html { redirect_to(product_pcolors_path(@product)) }
      format.xml  { head :ok }
    end
  end

  private

  def load_product
    @product = Product.find(params[:product_id])
  end
end
